Ext.define('WebOs.ex.DefaultGridStore', {
	extend : 'Ext.data.Store',
	/**
	 * 添加store请求参数
	 */
	addRequestParams : function(params){
		var me = this;
		var proxy = me.getProxy();
		for(var p in params){
			proxy.setExtraParam(p,params[p]);
		}
		return me;
	},
	/**
	 * 恢复store的请求参数至初始化状态
	 */
	resetRequestParams : function(){
		var me = this;
		var proxy = me.getProxy();
		var params = proxy.extraParams;
		for (var p in params){
			proxy.setExtraParam(p,null);
		}
		for (var p in me.storeParams){
			proxy.setExtraParam(p,me.storeParams[p]);
		}
		if(me.defaultSortProperty){
			proxy.setExtraParam('sort','[{property: "' +me.defaultSortProperty+ '",direction: "'+ me.defaultSortDirection+'"}]');
		}
	},
	
	
	
	defaultSortDirection : 'ASC',
	defaultSortProperty : null,
	
	constructor : function(cfg){
		var me = this;
		if(cfg!=null){
			Ext.apply(me,cfg);
		}
		me.storeParams = me.storeParams || {};
		if(me.defaultSortProperty){
			Ext.applyIf(me.storeParams,{
				sort:'[{property: "' +me.defaultSortProperty+ '",direction: "'+ me.defaultSortDirection+'"}]'
			})
		}
		var params = Ext.applyIf(me.storeParams,{
			'isPage' : false
		});
		me.callParent([
			{
				pageSize : me.pSize || Constants.DEFAULT_PAGE_SIZE,
				autoLoad : false,
				remoteSort : true,
				proxy : {
					url : Constants.REQUEST_URL,
				    actionMethods : 'POST',
				    reader : {
						root : 'result',
						type : 'json',
						totalProperty : 'total'
					},
					type : 'ajax',
					extraParams : params
				}
			}
		]);
	},
	doRemove : function(args){
		var me = this;
		me.remove(args);
		me.load();
		if(me.data.length == 0){
			me.loadPage(((me.currentPage - 1) == 0 ? 1: (me.currentPage - 1)),{});
		}
	}
});
